$().ready(function () {
    let year = sessionStorage.getItem('exam_year')
    $('#year').val(year)
    validateRule();
});

$.validator.setDefaults({
    submitHandler: function () {
        save();
    }
});


function save() {
    $('#year').prop('disabled', false);
    $.ajax({
        cache: true,
        type: "POST",
        url: "/jzweb/examinationCost/save",
        data: $('#signupForm').serialize(),// 你的formid
        async: false,
        error: function (request) {
            parent.layer.alert("Connection error");
        },
        success: function (data) {
            $('#year').prop('disabled', true);
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                parent.layer.alert(data.msg)
            }

        }
    });

}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            name: {
                required: true
            }
        },
        messages: {
            name: {
                required: icon + "请输入姓名"
            }
        }
    })
}

var prefix = "/jzweb/examinationCost";
$(function () {
    //学校查询
    $('#orgName').selectPage({
        showField: 'name',
        keyField: 'name',
        data: prefix + '/selectSchool',
        //向服务端提交的参数中，增加已选中的
        //设置返回-1，意为通知服务端返回空列表，初始化时使用
        params: function () {
            var pv = $('#orgName').val();
            return pv;
        },
        eAjaxSuccess: function (d) {
            var result;
            if (d) result = d.data;
            else result = undefined;
            return result;
            add.js
        }
    });

});

$.get(
    '/jzweb/examinationCost/userProvinceSel',
    {type: 0},
    function (data) {
        let str = '';
        if (data.code == 0) {
            str = `<option value="">--请选择省份--</option>`;
            data.data.forEach(function (v) {
                str += `<option value="${v.name}">${v.name}</option>`
            })
        }
        $("#province").html(str)
        $('#province').comboSelect();
    }
)

function inn(province) {
    var profiles = $('#profile option:selected')
    var grade = profiles.val()
    $.ajax({
        type: "GET",
        url: "/jzweb/examinationCost/costStandard",
        data: {province: province, grade: grade},
        success: function (data) {
            var a = ''
            var b = ''
            a = '<option>' + data.costStandard + '</option>'
            b = '<option>' + data.returnCostStandard + '</option>'
            $('#priceStandard').html(a)
            $('#returnStandard').html(b)
            if (province == '') {
                $('#priceStandard').html('')
                $('#returnStandard').html('')
            }
        }
    })
}

$('#province').change(function () {
    inn($(this).val())
})

$.get(
    '/jzweb/examinationCost/userProvinceSel',
    {type: 1},
    function (data) {
        let str = '';
        if (data.code == 0) {
            str = `<option value="">--请选择城市--</option>`;
            data.data.forEach(function (v) {
                str += `<option value="${v.name}">${v.name}</option>`
            })
        }
        $("#city").html(str)
        $('#city').comboSelect();
    }
)


